#include <my_head.h>

int main(int argc, const char *argv[]){
    int id = 1001;
    char name[32] = "张三";
    int age = 18;
    // 用来存放格式化内容的数组
    char buff[100];
    snprintf(buff, sizeof(buff), "学号:[%d] 姓名:[%s] 年龄:[%d]", id, name, age);
    printf("buff = [%s]\n", buff);

    // 注意 snprintf 函数会对越界做检查
    // 做多格式化 size - 1 个字节
    char buff2[5];
    snprintf(buff2, sizeof(buff2), "abcdefg");
    printf("buff2 = [%s]\n", buff2); // abcd

    return 0;
}